import axios from '@/axios.js'

export function login(username, password) {
    const formData = new URLSearchParams();
    formData.append('username', username);
    formData.append('password', password);
    return axios.post("/user/login", formData, {
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
        }
    })
}

export function getAllUsers() {
    return axios.post("/user/getAllUsers")
}

export function logout() {
    return axios.post("/user/logout")
}

export function updatePassword(oldPassword, Password, repassword) {
    const formData = new URLSearchParams();
    formData.append('oldPassword', oldPassword);
    formData.append('Password', Password);
    formData.append('rePassword', repassword);
    return axios.post("/user/updatePassword", formData, {
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
        }
    })
}

export function getMenus() {
    return axios.get("/sys-menu/getAllMenu")
}

export function getClassList(current, size, queryParams) {
    console.log('发送 getClassList 请求，参数:', { current, size, ...queryParams });
    return axios.get('/classManagement/getClassList', {
        params: {
            current,
            size,
            ...queryParams, // 展开 teacher, classTime 等
        },
    });
}

export function addClass(classData) {
    return axios.post('/classManagement/addClass', classData)
}

export function getClassById(classId) {
    return axios.get(`/classManagement/getClass/${classId}`);
}

// 课次管理相关 API
export function getScheduleList(params) {
    console.log('发送 getScheduleList 请求，参数:', params);
    return axios.get('/sche/schedule', { params });
}

export function addSchedule(scheduleData) {
    return axios.post('/sche/schedule', scheduleData);
}

export function updateSchedule(id, scheduleData) {
    return axios.put(`/sche/schedule/${id}`, scheduleData);
}

export function deleteSchedule(id) {
    return axios.delete(`/sche/schedule/${id}`);
}

export function getCourses() {
    return axios.get('/sche/courses');
}
